package com.kedou.app;

import java.util.ArrayList;

import com.kedou.domain.User;
import com.kedou.net.PostFunderInfo;
import com.kedou.net.PostFunderList;
import com.kedou.util.NetworkUtil;
import com.kedou.util.PreferencesUtil;
import com.kedou.util.Util;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 投资人 界面
 * 
 * @author zhouchao
 * 
 */
public class InvestorActivity extends BaseActivity implements OnClickListener {
	/**
	 * 左侧 返回按钮
	 */
	private Button mBtnBack;
	/**
	 * 中间 Title
	 */
	private TextView mTvTitle;
	/**
	 * 右侧 设置
	 */
	private ImageView mImgSetting;
	/**
	 * 投资人ID
	 */
	private String funderId;
	/**
	 * 投资人名称
	 */
	private TextView mTvName;
	/**
	 * 投资人角色
	 */
	private TextView mTvRole;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_investor);
		funderId = getIntent().getStringExtra("funderId");
		initView();
		setListener();
		getDataFromServer();
	}

	/**
	 * 初始化View
	 */
	private void initView() {
		mBtnBack = (Button) findViewById(R.id.btn_back);
		mBtnBack.setVisibility(View.VISIBLE);
		mTvTitle = (TextView) findViewById(R.id.title);
		mTvTitle.setText(R.string.app_name);
		mImgSetting = (ImageView) findViewById(R.id.img_setting);
		mImgSetting.setVisibility(View.VISIBLE);
		mTvName = (TextView) findViewById(R.id.tv_investor_name);
		mTvRole = (TextView) findViewById(R.id.tv_role);
	}

	/**
	 * 设置监听器
	 */
	private void setListener() {
		mBtnBack.setOnClickListener(this);
	}

	/**
	 * 从服务端获取数据
	 */
	private void getDataFromServer() {
		mProgressDialog.show();
		if (NetworkUtil.isNetworkAvailable(InvestorActivity.this)) {
			new PostFunderInfo(PreferencesUtil.getString(this, "token"),
					PreferencesUtil.getString(this, "userId"), funderId,
					Config.SOURCE, Util.getImei(this),
					new PostFunderInfo.SuccessCallback() {

						@Override
						public void onSuccess(String msg, User user) {
							mProgressDialog.dismiss();
							mTvName.setText(user.getRealName());
							// TODO 领投人角色 待处理
						}
					}, new PostFunderInfo.FailCallback() {

						@Override
						public void onFail(String msg) {
							mProgressDialog.dismiss();
							Toast.makeText(InvestorActivity.this, msg,
									Toast.LENGTH_SHORT).show();
						}
					}, InvestorActivity.this);
		} else {
			Toast.makeText(this,
					getResources().getString(R.string.check_your_network),
					Toast.LENGTH_SHORT).show();
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_back:
			finish();
			break;

		}
	}
}
